#pragma once
#include "ProjectPlan/PPPreTask.h"
#include "ProjectPlan/PPTask.h"
#include <list>

namespace LBPROJ
{
    class CPreTask : public IPreTask
    {
        IMPLEMENT_REFCOUNTING(CPreTask)
    public:
        CPreTask(Type type, ITask* preTask);
        virtual ~CPreTask();

    public:
        virtual void SetOwner(IPreTaskGroup* pOwner);
        virtual CRefPtr<IPreTaskGroup> GetOwner() const;

        virtual const std::wstring& GetID() const;

        virtual Type GetType() const;

        virtual CRefPtr<ITask> GetPreTask() const;

        virtual time_t GetStart() const;
        virtual time_t GetFinish() const;
        virtual CRefPtr<ITimeSpan> GetTimeSpan() const;

        virtual time_t GetActualStart() const;
        virtual time_t GetActualFinish() const;
        virtual CRefPtr<ITimeSpan> GetActualTimeSpan() const;

        virtual bool Store(Data& data) const;

    protected:
        CWeakPtr<IPreTaskGroup> m_pOwner;
        CWeakPtr<ITask> m_pPreTask;
        Type m_type;

    private:
        mutable std::wstring m_id;
    };

    class CPreTaskGroup : public IPreTaskGroup
    {
        IMPLEMENT_REFCOUNTING(CPreTaskGroup)
    public:
        CPreTaskGroup();
        virtual ~CPreTaskGroup();

    public:
        virtual void SetOwner(ITask* pOwner);
        virtual CRefPtr<ITask> GetOwner() const;

        virtual bool AddItem(const CRefPtr<IPreTask>& pItem, const CRefPtr<ITimeSpan>& pSpan = nullptr);
        virtual void DelItem(const CRefPtr<IPreTask>& pItem);
        virtual void DelAllItem();
        virtual CRefPtr<Iterator<IPreTask*>> CreateIterator() const;

        virtual std::wstring GetErrorMessage() const;
        virtual std::wstring GetPreTaskGroupAsString() const;
        virtual void PreTaskGroupFromString(const std::wstring& str);

    protected:
        CWeakPtr<ITask> m_pOwner;
        std::list<CRefPtr<IPreTask>> m_preTaskList;

        std::wstring m_errorMsg;

    private:
    };
}
